object selection_sort {
  def main(args: Array[String]) {
    var my_array = Array(1, 9, 45, 7, 15, -5, 2, 74, -27, 10)
    my_array = selection_sort(my_array, my_array.size)
    for (a <- my_array)
      printf("%d ", a)
  println()
  }

  def selection_sort(array: => Array[Int], size: Int): Array[Int] = {
    for (i <- 0 until array.size) {
      var smallest = array(i)
      var smallest_index = i
      for (j <- i until array.size) {
        if (array(j) < smallest) {
          smallest = array(j)
          smallest_index = j
        }
      }
      var temp = array(i)
      array(i) = smallest
      array(smallest_index) = temp
    }
    return array
  }
}
